import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
//旋转数组；
public class text4 {
    public static int[] fun1(int[] nums,int k){
        while(k>0) {
            int last = nums[nums.length - 1];
            for (int i = nums.length - 1; i > 0; i--) {
                nums[i] = nums[i - 1];
            }
            nums[0] = last;
            k--;
        }
        return nums;
    }
    public static int[] nm(int[]nums,int k){
        int count=1;
        Queue<Integer> queue=new LinkedList<>();
            for(int i= nums.length-k;i< nums.length;i++){
            queue.offer(nums[i]);

        }
            for(int i=0;i<k;i++) {
                nums[i] = queue.poll();
            }
            for(int i= nums.length-k-1;i< nums.length;i++){
                int ret=count++;
               nums[i]=ret;
    }
            return nums;
    }
    public static void main(String[] args){
        int[] nums={1,2,3,4,5,6,7};
        int k=3;
        //int[] ret=fun1(nums,k);
        int[] ret=nm(nums,k);
        System.out.println(Arrays.toString(nums));
    }
}
